package com.atguigu.gmall.seckill.api;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.order.entity.OrderInfo;
import com.atguigu.gmall.seckill.entity.SeckillGoods;
import com.atguigu.gmall.seckill.service.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/api/inner/seckill")
public class SeckillGoodsApiController {

    @Autowired
    private SeckillGoodsService seckillGoodsService ;

    @GetMapping(value = "/findAllSeckillGoods")
    public Result<List<SeckillGoods>> findAllSeckillGoods(){
        List<SeckillGoods> seckillGoods = seckillGoodsService.findAllSeckillGoods() ;
        return Result.build(seckillGoods , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findBySkuId/{skuId}")
    public Result<SeckillGoods> findBySkuId(@PathVariable(value = "skuId") Long skuId) {
        SeckillGoods seckillGoods = seckillGoodsService.findBySkuId(skuId) ;
        return Result.build(seckillGoods , ResultCodeEnum.SUCCESS) ;
    }

    @GetMapping(value = "/findOrderInfoBySkuId/{skuId}")
    public Result<OrderInfo> findOrderInfoBySkuId(@PathVariable(value = "skuId") Long skuId) {
        OrderInfo orderInfo = seckillGoodsService.findOrderInfoBySkuId(skuId) ;
        return Result.build(orderInfo , ResultCodeEnum.SUCCESS) ;
    }

}
























